package com.yunhe.authority.service.office;

import com.yunhe.authority.domain.office.Office;
import com.yunhe.authority.model.housing.*;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.exception.ModelNotFoundException;
import com.yunhe.common.exception.ObjectNotFoundException;
import com.yunhe.common.exception.UniqueConstraintsException;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 厂房service
 * @author zhengbo
 * @date 2020/11/4 16:26
 */
public interface OfficeService {

    /**
     * 创建厂房并绑定企业
     * @param companyId 企业ID
     * @param office 厂房
     * @return Office
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    Office createOffice(Long realStationId, Long companyId, Office office) throws ObjectNotFoundException, UniqueConstraintsException;

    /**
     * 更新厂房
     * @param office
     * @return
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    Office updateOffice(Office office) throws UniqueConstraintsException;

    /**
     * 更新指定字段
     * @param id ID
     * @param buildingNumber 楼栋号
     * @param officeName 厂房编号
     * @param officeTitle 厂房名称
     * @param officeArea 厂房面积
     * @return  Office
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    Office updateSpecifyAttributes(Long id,
                        Long buildingNumber,
                        String officeName,
                        String officeTitle,
                        Double officeArea) throws ObjectNotFoundException;

    /**
     * 根据ID查询厂房
     * @param officeId 厂房ID
     * @return  Office
     */
    Office findById(Long officeId);

    /**
     * 根据企业ID查询厂房列表
     * @param companyId 企业ID
     * @return  Iterable<Office>
     */
    Iterable<Office> findByCompanyId(Long companyId) throws ObjectNotFoundException;

    /**
     * 根据ID删除厂房
     * @param id 厂房ID
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    void deleteById(Long id) throws ArgumentErrorException;

    /**
     * 通过真是电站ID 和厂房名称查询当前电站下是否存在对应的厂房信息
     * @param stationId
     * @param officeName
     * @return
     */
    Office findByStationIdAndOfficeName(Long stationId, String officeName);

    /**
     * 通过电站ID 和厂房名称查询当前电站下是否存在对应的厂房信息
     * @param stationId
     * @param officeTitle
     * @return
     */
    Office findByStationIdAndOfficeTitle(Long stationId, String officeTitle);

    /**
     * 通过真实园区ID 和厂房名称查询当前电站下是否存在对应的厂房信息
     * @param realStationId
     * @param officeTitle
     * @return
     */
    Office findByRealStationIdAndOfficeTitle(Long realStationId, String officeTitle);

    /**
     * 根据总园区id与厂房title查询厂房
     * @param stationId 总园区ID
     * @param officeTitle 厂房title
     */
    Office findOfficeByStationIdAndTitle(Long stationId, String officeTitle);

    /**
     * 厂房绑定电站
     * @param stationId
     * @param id
     */
    void bindStation(Long stationId, Long id);

    /**
     * 绑定企业
     * @param companyId
     * @param id
     */
    void bindCompany(Long companyId, Long id);

    /**
     * 解绑企业
     * @param companyId
     */
    void unbindCompany(Long companyId);

    Office createOfficeByStationId(Long stationId, Office office);

    /**
     * 根据真实园区查询厂房列表
     * @param id
     * @return
     */
    Iterable<Office> findOfficesByRealStationId(Long id);

    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    String setOfficeBooked(Long intentionId, Long chosenOffice, String companyName, String stauts) throws ArgumentErrorException, ModelNotFoundException;

    /**
     * @Description 根据筛选条件搜索厂房
     * @Param FilterCondition filterCondition
     * @Return List<Office>
     * @Date 2021/6/24 14:10
     */
    Iterable<OfficeBrief> getOfficeByCondition(FilterCondition filterCondition);

    /**
     * @Description 房源面积统计
     * @Param OfficeStatisticsCondition officeStatisticsCondition
     * @Return OfficeAreaStatistics
     * @Date 2021/6/24 17:45
     */
    OfficeAreaStatistics officeAreaStatistics(OfficeStatisticsCondition officeStatisticsCondition);

    List<OfficeVo> getOfficeByRealStationId(OfficeQueryCondition officeQueryCondition);

    Office findByCompanyIdAndOfficeId(Long companyId, Long officeId);

    /**
     * 查询此厂房是否已经绑定过企业了
     * @param officeId 厂房id
     * @return Office
     */
    Office isAlreadyBindCompany(Long officeId);

    /**
     * 根据真实园区id查询空置厂房
     * @param realStationId 真实园区id
     * @return Iterable<Office>
     */
    Iterable<Office> searchVacantOfficesByRealStationId(Long realStationId);

    void downOfficeUploadTemplate(Long exportPeopleId, HttpServletResponse httpServletResponse) throws IOException;

    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    void importOffice(MultipartFile file) throws IOException, ArgumentErrorException, InterruptedException;
}
